﻿using System;
using System.Collections.Generic;
using System.Data;
using Loki.Data;
using Luna.Data.Mappers;

namespace Luna.Data.Project.Mappers
{
    public class ProjectTaskMapper : LunaEntityMapper<ProjectTaskData, IProjectTaskData>
    {
        private const string PROJECT_ID = "ProjectID";
        private const string CODE = "Code";
        private const string NAME = "Name";
        private const string START = "StartDate";
        private const string END = "EndDate";
        private const string BUDGET = "Budget";

        public string GetAllByProjectRequest { get; set; }

        protected override void LoadCoreData(IProjectTaskData P_Entity, IDataRecord P_Record)
        {
            P_Entity.Budget = P_Record.GetDecimal(BUDGET);
            P_Entity.Code = P_Record.GetString(CODE);
            P_Entity.End = P_Record.GetDate(END);
            P_Entity.ProjectID = P_Record.GetGuid(PROJECT_ID);
            P_Entity.Start = P_Record.GetDate(START);
            P_Entity.Name = P_Record.GetString(NAME);
        }

        protected override void MapSaveParameters(IDatabaseCommand P_Command, IProjectTaskData P_Entity)
        {
            P_Command.AddParameter(PROJECT_ID, P_Entity.ProjectID);
            P_Command.AddParameter(CODE, P_Entity.Code);
            P_Command.AddParameter(NAME, P_Entity.Name);
            P_Command.AddParameter(START, P_Entity.Start);
            P_Command.AddParameter(END, P_Entity.End);
            P_Command.AddParameter(BUDGET, P_Entity.Budget);
            P_Command.AddParameter(IDParameterName, P_Entity.PK);
        }

        public IEnumerable<IProjectTaskData> GetAllByProject(IDbTransaction P_Transaction, Guid P_ProjectID)
        {
            return ExecuteGetAll(P_Transaction, GetAllByProjectRequest, c => c.AddParameter(PROJECT_ID, P_ProjectID));
        }
    }
}
